﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Maticsoft.DBUtility;


namespace download
{
    /// <summary>
    /// xiazai 的摘要说明
    /// </summary>
    public class xiazai : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            string ip =context.Request.UserHostAddress;
            string sql = "insert into download(ip,time) values('" + ip + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')";
            int k =DbHelperSQL.ExecuteSql(sql);
            if (k > 0) {
                context.Response.Redirect("Handler.ashx");
            }
               
            
            
           
        }
       
       
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
       
        public static string IPAddress
        {
            get
            {
                string userIP;
                // HttpRequest Request = HttpContext.Current.Request;
                HttpRequest Request = HttpContext.Current.Request; // ForumContext.Current.Context.Request;
                // 如果使用代理，获取真实IP
                if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
                    userIP = Request.ServerVariables["REMOTE_ADDR"];
                else
                    userIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (userIP == null || userIP == "")
                    userIP = Request.UserHostAddress;
                return userIP;
            }
        }
    }
}